#include<bits/stdc++.h>
using namespace std;
int t,n,m,len,limit,pmax;
int d[100005],v[100005],a[100005],p[100005];
int yeah[1005][1005],cover[10005];
bool chk(int k)
{
    if(d[k]>pmax)return false;
    if(v[k]*v[k]+2*a[k]*(pmax-d[k])<=limit*limit)return false;
    return true;
}
void opt(int k,int stp)
{
    for(int i=1;i<=m;i++)
        if(p[i]>=stp)
            yeah[k][i]=1;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int T=1;T<=t;T++)
    {
        bool flagAB=true;
        pmax=0;
        cin>>n>>m>>len>>limit;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]<0)flagAB=false;
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
            pmax=max(pmax,p[i]);
        }
        if(flagAB)
        {
            int ans=0;
            for(int i=1;i<=n;i++)
                if(chk(i))ans++;
            cout<<ans<<" "<<((ans==0)?m:m-1)<<'\n';
        }
        else
        {
            int ans=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==0)
                {
                    if(v[i]>limit)opt(i,d[i]);
                }
                else if(a[i]>0)
                {
                    int s=int((((long double)1.0*limit*limit)-((long double)1.0*v[i]*v[i]))/((long double)2.0*a[i]));
                    opt(i,s);
                }
                else if(a[i]<0)
                {
                    if(v[i]>limit)
                    {
                        int s=int((((long double)1.0*limit*limit)-((long double)1.0*v[i]*v[i]))/((long double)2.0*a[i]));
                        for(int j=1;j<=m;j++)
                            if(p[j]>=d[i]&&p[j]<=d[i]+s)yeah[i][j]=1;
                    }
                }
            }
            int cov=0;
            for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                    if(yeah[i][j]){ans++;cover[i]=0,cov++;break;}
            for(int tim=1;;tim++)
            {
                int cnt,maxx=0,maxj;
                for(int j=1;j<=m;j++)
                {
                    cnt=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(cover[i])continue;
                        if(yeah[i][j])cnt++;
                    }
                    if(cnt>maxx)maxx=cnt,maxj=j;
                }
                for(int i=1;i<=n;i++)
                    if(yeah[i][maxj])cover[0]+=1-cover[i],cover[i]=1;
                if(cover[0]==cov)
                {
                    cout<<ans<<" "<<m-tim<<'\n';
                    break;
                }
            }
            for(int i=1;i<=n;i++)cover[i]=1;
            cover[0]=0;
        }
    }
    return 0;
}
